/*
 * Copyright (c) 2012-2013, CS Bakery. All rights reserved.
 */

package testCase;

import org.junit.Test;
import junit.framework.TestCase;
import csBakery.*;

/*
 *	@release Final Release
 *	@author  Yip Tak Wai
 *	@version 1.0.3
 */

public class CostListTest extends TestCase{

	private CostList costlist;
	private String filename;
	
	@Test
	public void testOpen_CostListA(){
		//Test most typical case 1: 1-word name and integer cost
		filename = "test\\costlistA.txt";
		costlist = new CostList(filename);
		String result = "ItemA $5.0\nItemB $10.0\nItemC $15.0\nItemD $20.0\nItemE $25.0\n";
		assertEquals(result, costlist.toString());
	}
	
	@Test
	public void testOpen_CostListB(){
		//Test most typical case 2: 2-word name and decimal cost
		filename = "test\\costlistB.txt";
		costlist = new CostList(filename);
		String result = "Bagel $5.0\nBaguette $6.6\nAish Merahrah $7.7\nBanana Bread $4.4\nBara Brith bread $5.5\n";
		assertEquals(result, costlist.toString());
	}
	
	@Test
	public void testWrite_PriceListNew(){
		filename = "test\\pricelistC.txt";
		
		//Ensure that each pricelistC must be an empty .txt file
		CostList.clearFile(filename);
		
		costlist = new CostList(filename);
		costlist.addNewCost("ItemA", 10);
		costlist.addNewCost("ItemB", 20);
		costlist.addNewCost("ItemC", 20);
		costlist.addNewCost("ItemD", 30);
		
		String result = "ItemA $10.0\nItemB $20.0\nItemC $20.0\nItemD $30.0\n";
		assertEquals(result, costlist.toString());
		
		//Testing individual item
		assertEquals(10.0, costlist.getCost("ItemA"), 0);
		assertEquals(20.0, costlist.getCost("ItemB"), 0);
		assertEquals(20.0, costlist.getCost("ItemC"), 0);
		assertEquals(30.0, costlist.getCost("ItemD"), 0);
		assertEquals(0, costlist.getCost("butterfly"), 0);
	}
}
